package bandidong.bean;

import bandidong.dao.OrdersDAO;
import bandidong.dao.impl.OrdersDAOImpl;
import bandidong.model.Orders;
import bandidong.transfermodel.SearchOrdersTransferModel;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
@TransactionManagement(javax.ejb.TransactionManagementType.CONTAINER)
public class OrdersBean implements OrdersBeanRemote {
    
    @PersistenceContext(unitName = "persistenceUnit")
    EntityManager em;
    
    private OrdersDAO ordersDAO = null;
    
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public List<Orders> getAllOrders() {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.getAllOrders();
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Orders getOrderById(int orderId) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.getOrderById(orderId);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Orders addOrder(Orders order) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.addOrder(order);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String updateOrder(Orders order) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.updateOrder(order);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String deleteOrder(Orders order) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.deleteOrder(order);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public List<Orders> getOrdersCriteria(SearchOrdersTransferModel model, int page, int pageSize) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.getOrdersCriteria(model, page, pageSize);
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public List<Orders> getOrdersCriteria(SearchOrdersTransferModel model) {
        ordersDAO = new OrdersDAOImpl(em);
        return ordersDAO.getOrdersCriteria(model);
    }
}
